import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import "../component" as C
import "qrc:/component/ZGlobal.js" as Global

C.ZModelRect {
    id: rootWeightCalibrationPage
    radius: 20
    clip: true
    anchors.fill: parent
    visible: false
    color: "transparent"
    property int result: collectionInfo.result
    property int cmd: collectionInfo.cmd
    property int step: 0

    onVisibleChanged: {
        collectionInfo.setCollect(!visible);
        console.log("cmd:", cmd)
    }
    onCmdChanged: {
        //console.log(result, cmd);
        if(result === 1){    // 成功
            resultImg.source="qrc:/assets/success.png"
        }
        if(result === 2){    // 失败
            resultImg.source="qrc:/assets/failure.png"
        }

        if(cmd === 8){
            resultText.text = "电导1校准完成！"
        }

        if(cmd === 9){
            resultText.text = "电导2校准完成！"
        }
        step++;
    }

    Image {
        x:646;y:280;width:778;height:520;
        source: "qrc:/assets/ph_calibration_bg.png"

        Image {
            x: 687-parent.x
            y: 319-parent.y
            width: 16
            height: 32
            source: "qrc:/assets/greenrect.png"
        }

        Label{
            x:68
            y:36
            Text{
                text: "电导校准"
                font.pixelSize: 30
                color: "#191A1A"
                font.bold: true
            }
        }

        Image {
            id: closeBtn
            x: 1358-parent.x
            y: 317-parent.y
            width: 24
            height: 24
            property bool pressed: false
            scale: pressed ? 0.90 : 1
            source: "qrc:/assets/close.png"
            MouseArea{
                anchors.fill: parent
                onPressed: closeBtn.pressed=true
                onReleased: closeBtn.pressed=false
                onClicked: {
                    console.log("close")
                    rootWeightCalibrationPage.visible=false
                }
            }
        }

        Image {
            x: 812-parent.x
            y: 394-parent.y
            width: 65
            height: 60
            source: "qrc:/assets/step1.png"
        }

        Image {
            id: step2Img
            x: 1172-parent.x
            y: 394-parent.y
            width: 65
            height: 60
            source: "qrc:/assets/step2_colorful.png"
        }


        Label{
            x:784-parent.x
            y:478-parent.y
            Text{
                text: "0.000 mS/cm"
                font.pixelSize: 34
                color: "#178FCD"
                font.bold: true
            }
        }
        Label{
            x:1144-parent.x
            y:478-parent.y
            Text{
                text: "12.880 mS/cm"
                font.pixelSize: 34
                color: "#178FCD"
                font.bold: true
            }
        }

        Label{
            x:970-parent.x
            y:634-parent.y
            Text{
                id: resultText
                text: "CP1校准完成！"
                font.pixelSize: 30
                color: "#178FCD"
            }
            visible: step != 0
        }

        Image {
            id: imgBtn1
            property bool pressed: false
            x: 737-parent.x
            y: 540-parent.y
            width: 232
            height: 72
            scale: pressed ? 0.98 : 1
            source: "qrc:/assets/button_calibration.png"
            Label{
                x:816-parent.x-parent.parent.x
                y:558-parent.y-parent.parent.y
                Text{
                    text: "校准1"
                    font.pixelSize: 22
                    color: "#FFFFFF"
                }
            }
            MouseArea{
                anchors.fill: parent
                onPressed: imgBtn1.pressed=true
                onReleased: imgBtn1.pressed=false
                onClicked: {
                    console.log("1点校准")
                    collectionInfo.conductivityCalibration1();
                }
            }
        }
        Image {
            id: imgBtn2
            property bool pressed: false
            x: 1093-parent.x
            y: 536-parent.y
            width: 232
            height: 72
            scale: pressed ? 0.98 : 1
            source: "qrc:/assets/button_calibration.png"
            Label{
                x:1176-parent.x-parent.parent.x
                y:558-parent.y-parent.parent.y
                Text{
                    text: "校准2"
                    font.pixelSize: 22
                    color: "#FFFFFF"
                }
            }
            MouseArea{
                anchors.fill: parent
                onPressed: imgBtn2.pressed=true
                onReleased: imgBtn2.pressed=false
                onClicked: {
                    console.log("2点校准")
                    collectionInfo.conductivityCalibration2();
                }
            }
        }

        Image {
            id: resultImg
            x: 914-parent.x
            y: 626-parent.y
            width: 48
            height: 48
            source: "qrc:/assets/success.png"
            visible: step !=0
        }

        Label{
            x:702-parent.x
            y:700-parent.y
            Text{
                id: descText
                text: "注：当前pH值的斜率：xxxxxx\n质量指数：xxxxxx"
                font.pixelSize: 22
                color: "#6D7278"
            }
        }
    }

}

